package com.hunt.controller;

import com.hunt.model.entity.NewsQuick;
import com.hunt.service.NewsQuickService;
import com.hunt.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.http.client.utils.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @Author sjs
 * @Date 2020/10/9 17:05
 * @Description
 */
@Api(value = "手机app端,新闻管理模块")
@Controller
@RequestMapping(path = "/app/news")
public class NewsController extends BaseController {

    @Autowired
    @Resource
    private NewsQuickService newsQuickService;
    private static final Logger log = LoggerFactory.getLogger(NewsController.class);

    @ApiOperation(value = "新闻快讯列表查询", httpMethod = "GET", produces = "application/json", response = Result.class)
    @ResponseBody
    @RequestMapping(value = "findNewsQuick", method = RequestMethod.GET)
    public Result findNewsQuick(@RequestParam(value = "dateTime",required = false) String dateTime,
                                @RequestParam(value = "sizeUP", defaultValue = "10") Integer sizeUP) throws ParseException {
        if(dateTime==null){
            Date da=new Date();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            List<NewsQuick> newsQuickList = newsQuickService.findNewsQuickByPage(sdf.format(da),sizeUP);
            log.info(sdf.format(da));
            return Result.success(newsQuickList);
        }
        else {
            List<NewsQuick> newsQuickList = newsQuickService.findNewsQuickByPage(dateTime,sizeUP);
            log.info(dateTime);
            return Result.success(newsQuickList);
        }
    }
}
